mui.init();
mui.plusReady(function(){
			mui.getJSON ("json/locat.json", function (data) {
			var sessionId=(plus.navigator.getCookie("sessionId")==null)?"":plus.navigator.getCookie("sessionId");
			var  locat=data["url"];
				var factoryid=data["factoryid"];
			var factoryId=(plus.navigator.getCookie("factoryid")==null)?"":plus.navigator.getCookie("factoryid");
					if(factoryId != factoryid)
					window.location.href="login.html";
	        	mui.ajax(locat+"/clientUser/client_list?sessionId="+sessionId, {
		            type: "GET",
		            success: function(data, status, xhr) {
							if("error" == data["msg"]) 
								window.location.href = "login.html";
							else{
								var finallist=""
								for(i = data["list_client"].length - 1; i >= 0; i--) {
								    finallist+="<div class=\"am-panel am-panel-default\"  >"+
										    "<div class=\"am-panel-hd\">"+
										    "  <h4 onclick='findorderlist(\"" + data['list_client'][i]['c_id'] + "\",\"" + data['list_client'][i]['clientnumber'] + "\",\"" + data['list_client'][i]['clientname'] + "\")'    class=\"am-panel-title\" data-am-collapse=\"{parent: '#accordion', target: '#div_"+ data['list_client'][i]['clientnumber']+"'}\">"+data["list_client"][i]["clientname"]+"  <span class=\"am-fr\">查看订单<i class=\"am-icon-angle-right am-icon-sm am-icon-left\"></i></span>  "+
										     " </h4>  "+
										    "</div> " +
										    "<div id=\"div_"+ data['list_client'][i]['clientnumber']+"\" class=\"am-panel-collapse am-collapse\">   "+
										    "<div class=\"am-panel-bd\" ></div>              "+
										    "  </div>   "+
										  "</div>";
								}
								$("#accordion").append(finallist);
							}
					
			            },
			            error:function(data){
			            	swal("","服务异常","error");
				            window.location.href=login.html;
			            }
	        	});
    		});  
			
		});
		
//加载 大票号		
function findorderlist(c_id,clientnumber,clientname){
		if($("#flag").val()=="0" ||($("#flag").val().indexOf('div_'+clientnumber) < 0)){
			var id = "body-loading";
	  		$(window).loading({action:"open",id:id,font:40}); 
			mui.getJSON ("json/locat.json", function (data) {
				var sessionId=(plus.navigator.getCookie("sessionId")==null)?"":plus.navigator.getCookie("sessionId");
					var  locat=data["url"];
						var factoryid=data["factoryid"];
			var factoryId=(plus.navigator.getCookie("factoryid")==null)?"":plus.navigator.getCookie("factoryid");
					if(factoryId != factoryid)
					window.location.href="login.html";
		        	mui.ajax(locat+"/clientUser/ordr_list?clientnumber="+clientnumber+"&factoryid="+factoryid+"&sessionId="+sessionId, {
			            type: "GET",
			            xhrFields: {
			                withCredentials: true,
			                useDefaultXhrHeader: false
			            },
			            crossDomain: true,
			            success: function(data, status, xhr) {
			            		var time = setTimeout(function(){
				   				//关闭
				   					$(window).loading({action:"close",id:id});
				   				},100);
								if("error" == data["msg"]) 
									window.location.href = "login.html";
								else{
									var finallist=" <ul class=\"am-list\">   	";
									if(data["json_card_orders"].length ==0){
										
									
										sweetAlert("订单获取失败", "请先去工厂下单", "error");
										finallist+="<li class=\"am-g am-list-item-desced am-list-item-thumbed am-list-item-thumb-left\">  "+  
													      "  <div class=\" am-u-sm-12 am-list-main\">"+
													      "      <h3 class=\"am-list-item-hd\">"+
													      "      	<a href=\"#\"  disabled='true'>订单编号：无</a>"+
													      "      </h3>"+
													      "      <div class=\"am-list-item-texta\">"+
													      "      	<span class=\"am-time\">开票时间：无</span><br />"+
													      "      	<span class=\"am-spmc\">商品名称：无</span><br />"+
													      "      	<span class=\"am-sysl\">剩余数量：0吨</span><br />    "+        	          	
													      "      	</div>"+
													      "  </div>"+
													     " </li>";
									}
									else{
										
										for(i = data["json_card_orders"].length - 1; i >= 0; i--) {
										    finallist+="<li class=\"am-g am-list-item-desced am-list-item-thumbed am-list-item-thumb-left\">  "+  
													      "  <div class=\" am-u-sm-12 am-list-main\">"+
													      "      <h3 class=\"am-list-item-hd\">"+
													      "      	<a href=\"#\" disabled='true' class=\"\">订单编号："+data["json_card_orders"][i]["billnumber"]+"</a>"+
													      "      </h3>"+
													      "      <div class=\"am-list-item-texta\">"+
													      "      	<span class=\"am-time\">开票时间："+data["json_card_orders"][i]["setdate"]+"</span><br />"+
													      "      	<span class=\"am-spmc\">商品名称："+data["json_card_orders"][i]["stockname"]+"</span><br />"+
													      "      	<span class=\"am-sysl\">剩余数量："+data["json_card_orders"][i]["maxnumber"]+"吨</span><br />    "+        	          	
													      "      	</div>"+
													      "      	<button type=\"button\" onclick='place_order(\"" + data['json_card_orders'][i]['stockno'] + "\",\"" + data['json_card_orders'][i]['stockname'] + "\",\"" + data['json_card_orders'][i]['billnumber'] + "\",\"" + data['json_card_orders'][i]['maxnumber'] + "\",\"" + clientname+ "\" ,\"" + clientnumber+ "\" ,\"" + c_id+ "\"       )' class=\"am-btn am-th am-radius am-fr am-btn-secondary\">我要提货</button>	"+
													     
													      "  </div>"+
													     " </li>";
										}
									}
									finallist+="</ul>"
									$("#flag").val('div_'+clientnumber+","+$("#flag").val())//flag 赋值;
									$('#div_'+clientnumber).empty(); //移除节点内的子元素
									$('#div_'+clientnumber).append(finallist);
								}
						
				            },
				            error:function(data){
				            	var time = setTimeout(function(){
				   				//关闭
				   					$(window).loading({action:"close",id:id});
				   				},100);
				            	swal("","服务异常","error");
				            	window.location.href=login.html;
				            }
		        	});
	    	});  
		}else {
			//什么都不做；
		}
		
}

//进入下单页面
function place_order(stockno,stockname,billnumber,maxnumber,clientname,clientnumber,c_id){
	var params="?stockname="+escape(stockname)+"&billnumber="+billnumber+"&maxnumber="+maxnumber+"&clientname="+escape(clientname)+"&clientnumber="+clientnumber+"&stockno="+stockno+"&c_id="+c_id;  
	window.location.href = "xthd.html"+params;
}

//新增大票号
function addorder(){
	sweetAlert("网上下单业务未开启", "", "error");
}



